package com.ftg.exam.manage.controller;

import com.ftg.exam.manage.service.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zwl
 * Created on 2019/8/13 11:35
 */
@RestController
@CrossOrigin
@RequestMapping("/excel")
public class ImportExcelController {
    @Autowired
    ImportService importService;

    /**
     * excel单项选择
     * @param file
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/import")
    @ResponseBody
    public Map<String, Object> importExcel(@RequestParam(value="file",required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response){
        Map<String, Object> map = new HashMap<String, Object>();
        String result = importService.OneFile(file);
        map.put("message", result);
        return map;
    }

    /**
     * excel多项选择
     * @param file
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/mul")
    @ResponseBody
    public Map<String, Object> importMultipleExcel(@RequestParam(value="file",required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response){
        Map<String, Object> map = new HashMap<String, Object>();
        String result = importService.MultipleFile(file);
        map.put("message", result);
        return map;
    }
}
